package com.xmotor.testmvcintercepter.intercepter;

import com.xmotor.testmvcintercepter.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
public class TestInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("拦截器preHandler...");
        User user = new User().setId(1).setName("Tony");
        request.setAttribute("user",user);
        return true;
    }
}
